package com.tigercel.xiangchengyun.ui.fragments

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.tigercel.xiangchengyun.R
import com.tigercel.xiangchengyun.adapter.ChannelSubAdapter
import com.tigercel.xiangchengyun.entity.ChannelSub
import kotlinx.android.synthetic.main.fragment_channel_sub.*


class ChannelSubFragment : Fragment() {

    companion object {
        fun newInstance(index: Int): ChannelSubFragment? {
            val fragment = ChannelSubFragment()
            val bundle = Bundle()
            bundle.putInt("index", index)
            fragment.arguments = bundle
            return fragment
        }
    }
    private var containerView: View? = null
    private var index: Int = 0
    private var newsChannels1: MutableList<ChannelSub>? = null
    private var newsChannels2: MutableList<ChannelSub>? = null
    private var newsChannels3: MutableList<ChannelSub>? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {

        containerView = inflater.inflate(R.layout.fragment_channel_sub, container, false)
        if (arguments != null)
            index = arguments!!.getInt("index")
        return containerView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        recyclerView.layoutManager = LinearLayoutManager(activity)
        newsChannels1 = ArrayList()
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"项城","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"政情","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"福利","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"天下","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"生活","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"直播","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"专题","",true))
        newsChannels1!!.add(ChannelSub(R.mipmap.ic_launcher,"VR全景","",true))

        newsChannels2 = ArrayList()

        newsChannels3 = ArrayList()
        newsChannels3!!.add(ChannelSub(R.mipmap.ic_launcher,"共享","共享",false))

        if (index == 0){
            recyclerView.adapter = ChannelSubAdapter(newsChannels1 as ArrayList<ChannelSub>) {
            }
        } else if (index == 1) {
            recyclerView.adapter = ChannelSubAdapter(newsChannels2 as ArrayList<ChannelSub>) {
            }
        } else {
            recyclerView.adapter = ChannelSubAdapter(newsChannels3 as ArrayList<ChannelSub>) {
            }
        }




    }
}
